import type { PlusColumn } from 'plus-pro-components'

import { agreementStatusEnum } from '../constant'

import { createMapEnum } from '../mapEnum'
import { isPurchaser, isSupplier } from './use-role'

const agreementStateMap = createMapEnum(agreementStatusEnum)

export function useForm() {
    const schema: PlusColumn[] = [
        {
            colProps: {
                span: 6,
            },
            label: '状态',
            options: agreementStateMap.options,
            prop: 'status',
            valueType: 'select',
        },

        {
            colProps: {
                span: 6,
            },
            label: '协议名称',
            prop: 'agreementName',
            valueType: 'copy',
        },

        {
            colProps: {
                span: 6,
            },
            label: '协议编号',
            prop: 'agreementCode',
            valueType: 'copy',
        },
        {
            colProps: {
                span: 6,
            },
            label: '甲方',
            prop: 'partyA',
            valueType: 'copy',
            hideInForm: isPurchaser.value,
        },
        {
            colProps: {
                span: 6,
            },
            label: '乙方',
            prop: 'partyB',
            valueType: 'copy',
            hideInForm: isSupplier.value,
        },
        {
            colProps: {
                span: 6,
            },
            label: '发起时间',
            prop: 'daterange',
            valueType: 'date-picker',
            fieldProps: {
                type: 'daterange',
                rangeSeparator: '-',
                valueFormat: 'YYYY-MM-DD',
            },
        },
    ] as const

    const state = {
        agreementCode: '',
        agreementName: '',
        agreementType: 1,
        status: '',
        partyA: '',
        partyB: '',
        daterange: [],
        type: 0,

    }
    const form = ref({
        ...state,
    })

    function reset() {
        form.value = {
            ...state,
        }
    }

    return { form, reset, schema, state }
}
